package cn.udesk.web.controller;

import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/view/")
public class PageController {

  @Value("${login.title}")
  private String loginTitle;


  @RequestMapping("indexUI.shtml")
  public String IndexUI(HttpSession session) {
    session.setAttribute("loginTitle", loginTitle);
    return "index";
  }

  @RequestMapping("mainUI.shtml")
  public String mainUI() {
    return "main";
  }

  @RequestMapping("loginUI.shtml")
  public String loginUI(@ModelAttribute("errorMsg") String errorMsg, HttpSession session) {
    session.setAttribute("errorMsg", errorMsg);
    session.setAttribute("loginTitle", loginTitle);
    return "login";
  }

  /** ==========trans start ========== **/

  @RequestMapping("trans/listUI.shtml")
  public String transListUI() {
    return "trans/list";
  }

  @RequestMapping("trans/rAddUI.shtml")
  public String transRAddUI() {
    return "trans/r-add";
  }

  @RequestMapping("trans/fAddUI.shtml")
  public String transFAddUI() {
    return "trans/f-add";
  }

  @RequestMapping("trans/editUI.shtml")
  public String transEditUI(Integer transId, Model model) {
    model.addAttribute("transId", transId);
    return "trans/edit";
  }

  /** ==========trans end ========== **/

  /** ==========user start========== **/

  @RequestMapping("user/listUI.shtml")
  public String userListUI() {
    return "user/list";
  }

  @RequestMapping("user/addUI.shtml")
  public String userAddUI() {
    return "user/add";
  }

  @RequestMapping("user/editUI.shtml")
  public String userEditUI(Integer userId, Model model) {
    model.addAttribute("uId", userId);
    return "user/edit";
  }

  /** ==========user end========== **/

  /** ==========record start========== **/

  @RequestMapping("trans/record/listUI.shtml")
  public String transRecordListUI(Integer transId, Model model) {
    model.addAttribute("transId", transId);
    return "record/t-list";
  }

  /** ==========record end========== **/

  /** ==========monitor start========== **/

  @RequestMapping("trans/monitor/listUI.shtml")
  public String transMonitorListUI() {
    return "monitor/t-list";
  }

  /** ==========monitor start========== **/
}
